package com.developmentReformProject.service.impl;

/***********************************************************************
 * Module:  AdminServiceImpl.java
 * Author:  胡志鹏
 * Purpose: Defines the Class AdminServiceImpl
 ***********************************************************************/

import com.developmentReformProject.dao.AdminDao;
import com.developmentReformProject.dao.EnterpriseDao;
import com.developmentReformProject.dto.AdminDto;
import com.developmentReformProject.dto.AdminQueryDto;
import com.developmentReformProject.dto.LogQueryDto;
import com.developmentReformProject.entity.Admin;
import com.developmentReformProject.entity.Enterprise;
import com.developmentReformProject.service.AdminService;
import com.developmentReformProject.utils.PageUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
@Slf4j
/** @pdOid 194f9f97-1cc1-4bcf-ac0f-b8da8ed22447 */
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminDao adminDao;
    @Autowired
    private EnterpriseDao enterpriseDao;


    public String deleteLog() {
        // TODO: implement
        return null;
    }

    /** @param adminPower
     * @pdOid 0a0de2a4-00d3-4ce3-b901-cab53e73c515 */
    public List<AdminDto> queryAdminByPower(int adminPower) {
        adminDao.queryAdminByPower(adminPower);
        return null;
    }

    /** @param logId
     * @pdOid df5a2c73-f500-4288-a09b-a9e43f24c666 */
    public LogQueryDto queryLogById(Integer logId) {
        // TODO: implement
        return null;
    }

    public String deleteEnterpriseBatchAdmin(int[] enterpriseIds) {
        enterpriseDao.deleteEnterpriseBatch(enterpriseIds);
        return null;
    }

    @Override
    public String queryAllStateAdmin() {
        adminDao.queryAllStateAdmin();
        return null;
    }

    @Override
    public PageUtil<Admin> pageList(AdminQueryDto adminQueryDto) throws Exception {
        PageUtil<Admin> pageUtil=null;
        //统计满足条件记录总数
        int total=adminDao.countSelective(adminQueryDto);
        /*
         * 如果total>0,查询数据
         * 封装到pageUtil
         */
        if(total>0){
            List<Admin> data=adminDao.selectSelective(adminQueryDto);
            pageUtil=new PageUtil<>(total, data, adminQueryDto.getCurrentPage(), adminQueryDto.getPageSize());
        }
        return pageUtil;
    }

    /** @param enterpriseId
     * @pdOid 01d333c2-debc-4f49-a8ee-89f8f1cd339d */
    public String deleteEnterpriseAdmin(Integer enterpriseId) {
        enterpriseDao.deleteEnterprise(enterpriseId);
        return null;
    }

    /** @param enterprise
     * @pdOid 127477e8-9967-4f16-8c72-52fe2ef5a217 */
    public String updateEnterpriseAdmin(Enterprise enterprise) {
        enterpriseDao.updateEnterprise(enterprise);
        return null;
    }

    /** @param
     * @pdOid 243601ec-825a-4933-9756-6dce82800cc0 */
    public String updatePasswordAdmin(String accountNumber,String newPassword,String oldPassword) {
        String adminPassword=adminDao.queryPassword(accountNumber);
        if(adminPassword!=null) {
            if (adminPassword.equals(oldPassword)) {
                adminDao.updateAdminPassword(accountNumber, newPassword);
            } else {
                return "0";
            }
        }
        return "1";
    }

    @Override
    public Enterprise selectEnterpriseAdmin(Integer enterpriseId) {
        enterpriseDao.queryEnterprise(enterpriseId);
        return null;
    }

    /** @param adminDto
     * @pdOid 07058545-5fde-4ae1-ae8b-ea9e78abcd54 */
    public String logoutAdmin(AdminDto adminDto) {
        // TODO: implement
        return null;
    }

    /** @param adminAccountNumber
     * @param adminPassword
     * @pdOid bea702e9-b4cc-4144-87e4-683846e09a8e */
    public String loginAdmin(String adminAccountNumber, String adminPassword) {
        String mag=null;
        Admin login=adminDao.adminLogin(adminAccountNumber,adminPassword);
        if(login!=null){
            mag="yes";
        }
        return mag;
    }

    /** @param projectId
     * @pdOid eaab2073-fd54-483a-aae8-e65b827958ea */
    public String toExamine(Integer projectId) {
        return null;
    }

    /** @param operationType
     * @pdOid 71864e29-bfe7-40b3-9fc7-e0c7df166cd2 */
    public List<LogQueryDto> queryOperationByType(String operationType) {
        // TODO: implement
        return null;
    }

    /** @param visitDate
     * @pdOid e9d85cee-64b1-49f3-a3df-c49dcb0a1ffb */
    public List<LogQueryDto> queryLogByVisitDate(Date visitDate) {
        // TODO: implement
        return null;
    }


    /**
     * 通过管理员id查找管理员
     * @param admin
     * @return
     */
    public AdminDto queryAdminById(Integer admin) {
        adminDao.queryAdmin(admin);
        return null;
    }

    /**
     * 通过管理员编号批量删除管理员
     * @param
     * @return
     */
    public String deleteAdminBatch(int[] adminNos) {
        adminDao.deleteAdminBatch(adminNos);
        return "删除成功";
    }

    /**
     * 通过管理员编号删除管理员
     * @param adminNo
     * @return
     */
    public String deleteAdmin(Integer adminNo) {
        adminDao.deleteAdmin(adminNo);
        return "删除成功";
    }

    /**
     * 修改管理员信息
     * @param
     * @return
     */
    public String updateAdmin(int adminNo,Admin admin) {
        admin.setAdminNo(adminNo);
        adminDao.updateAdmin(admin);
        return "1";
    }

    /**
     * 添加管理员
     * @param admin
     * @return
     */
    public String addAdmin(Admin admin) {
        adminDao.addAdmin(admin);
        return "1";
    }
    public Admin queryByUsername(String username){

        return adminDao.queryByUsername(username);
    }

    @Override
    public PageUtil<Admin> cleanAdmin(AdminQueryDto adminQueryDto) throws Exception {
        PageUtil<Admin> pageUtil=null;
        //统计满足条件记录总数
        int total=adminDao.countClean(adminQueryDto);
        /*
         * 如果total>0,查询数据
         * 封装到pageUtil
         */
        if(total>0){
            List<Admin> data=adminDao.listDelete(adminQueryDto);
            pageUtil=new PageUtil<>(total, data, adminQueryDto.getCurrentPage(), adminQueryDto.getPageSize());
        }
        return pageUtil;
    }

}
